Dart Map operator ==
Syntax & Examples


Syntax of Map.operator ==

The syntax of Map.operator == operator is:

operator ==(Object other) → bool

This operator == operator of Map the equality operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe object to compare against


✐ Examples

1 Check equality of two numbers

In this example,

  1. We declare two integers, num1 and num2, with values 10 and 20 respectively.
  2. We then use the equality operator == to compare num1 and num2.
  3. Since num1 is not equal to num2, the result is false.
  4. We print the result to standard output.

Dart Program

void main() {
  int num1 = 10;
  int num2 = 20;
  bool result = num1 == num2;
  print('Are num1 and num2 equal? $result');
}

Output

Are num1 and num2 equal? false

2 Check equality of two strings

In this example,

  1. We declare two strings, str1 and str2, with values 'hello' and 'world' respectively.
  2. We then use the equality operator == to compare str1 and str2.
  3. Since str1 is not equal to str2, the result is false.
  4. We print the result to standard output.

Dart Program

void main() {
  String str1 = 'hello';
  String str2 = 'world';
  bool result = str1 == str2;
  print('Are str1 and str2 equal? $result');
}

Output

Are str1 and str2 equal? false

3 Check equality of two lists

In this example,

  1. We declare two lists, list1 and list2, containing integers 1, 2, and 3.
  2. We then use the equality operator == to compare list1 and list2.
  3. Since list1 is equal to list2, the result is true.
  4. We print the result to standard output.

Dart Program

void main() {
  List<int> list1 = [1, 2, 3];
  List<int> list2 = [1, 2, 3];
  bool result = list1 == list2;
  print('Are list1 and list2 equal? $result');
}

Output

Are list1 and list2 equal? true

Summary

In this Dart tutorial, we learned about operator == operator of Map: the syntax and few working examples with output and detailed explanation for each example.